<template>
  <div class="sidebar" :class="{ collapsed: isCollapsed }">
    <div class="sidebar-header">
      <h2 v-if="!isCollapsed">工具集合</h2>
      <button class="toggle-btn" @click="toggleSidebar">
        <span v-if="isCollapsed">☰</span>
        <span v-else>‹</span>
      </button>
    </div>
    
    <nav class="sidebar-nav">
      <div class="nav-group">
        <div class="nav-group-title" v-if="!isCollapsed">
          <span class="group-icon">🌐</span>
          Web
        </div>
        <router-link 
          to="/url-encoder" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? 'URL 编码/解码' : ''"
        >
          <span class="nav-icon">🔗</span>
          <span v-if="!isCollapsed" class="nav-text">编码/解码URL格式的字符串</span>
        </router-link>
      </div>
      
      <div class="nav-group">
        <div class="nav-group-title" v-if="!isCollapsed">
          <span class="group-icon">📱</span>
          图片和视频
        </div>
        <router-link 
          to="/qr-generator" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? '二维码生成器' : ''"
        >
          <span class="nav-icon">📱</span>
          <span v-if="!isCollapsed" class="nav-text">二维码生成器</span>
        </router-link>
      </div>
      
      <div class="nav-group">
        <div class="nav-group-title" v-if="!isCollapsed">
          <span class="group-icon">⚙️</span>
          开发
        </div>
        <router-link 
          to="/properties-converter" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? 'Properties转换' : ''"
        >
          <span class="nav-icon">🔄</span>
          <span v-if="!isCollapsed" class="nav-text">Properties转换</span>
        </router-link>
        <router-link 
          to="/base64-converter" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? 'Base64和文件互转' : ''"
        >
          <span class="nav-icon">🔐</span>
          <span v-if="!isCollapsed" class="nav-text">Base64和文件互转</span>
        </router-link>
        <router-link 
          to="/crontab-generator" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? 'Crontab表达式生成' : ''"
        >
          <span class="nav-icon">⏰</span>
          <span v-if="!isCollapsed" class="nav-text">Crontab表达式生成</span>
        </router-link>
        <router-link 
          to="/text-converter" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? '文字转换' : ''"
        >
          <span class="nav-icon">📝</span>
          <span v-if="!isCollapsed" class="nav-text">文字转换</span>
        </router-link>
      </div>
      
      <div class="nav-group">
        <div class="nav-group-title" v-if="!isCollapsed">
          <span class="group-icon">🔄</span>
          转换
        </div>
        <router-link 
          to="/rmb-converter" 
          class="nav-item"
          :class="{ 'nav-item-collapsed': isCollapsed }"
          :title="isCollapsed ? '人民币金额转换' : ''"
        >
          <span class="nav-icon">💰</span>
          <span v-if="!isCollapsed" class="nav-text">人民币金额转换</span>
        </router-link>
      </div>
    </nav>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const isCollapsed = ref(false)

const toggleSidebar = () => {
  isCollapsed.value = !isCollapsed.value
}
</script>

<style scoped>
.sidebar {
  width: 280px;
  height: 100vh;
  background: #2c3e50;
  color: white;
  transition: width 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sidebar.collapsed {
  width: 60px;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid #34495e;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 60px;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.2rem;
  white-space: nowrap;
}

.toggle-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.toggle-btn:hover {
  background-color: #34495e;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-group {
  margin-bottom: 1.5rem;
}

.nav-group-title {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: bold;
  color: #bdc3c7;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.group-icon {
  font-size: 1rem;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  color: #ecf0f1;
  text-decoration: none;
  transition: all 0.2s;
  gap: 0.75rem;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  background-color: #34495e;
  border-left-color: #3498db;
}

.nav-item.router-link-active {
  background-color: #3498db;
  border-left-color: #2980b9;
}

.nav-item-collapsed {
  justify-content: center;
  padding: 0.75rem 0.5rem;
}

.nav-icon {
  font-size: 1.2rem;
  min-width: 20px;
  text-align: center;
}

.nav-text {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
}

/* 滚动条样式 */
.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: #2c3e50;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #34495e;
  border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: #4a5f7a;
}

@media (prefers-color-scheme: dark) {
  .sidebar {
    background: #1a1a1a;
    border-right: 1px solid #333;
  }
  
  .sidebar-header {
    border-bottom-color: #333;
  }
  
  .toggle-btn:hover {
    background-color: #333;
  }
  
  .nav-item:hover {
    background-color: #333;
  }
}
</style>